﻿using UnityEngine;

public partial class PlayerController : MonoBehaviour
{

    private int runAnimID = Animator.StringToHash("running");
    private int jumpAnimID = Animator.StringToHash("jumping");
    private int fallAnimID = Animator.StringToHash("falling");


    void SwitchAnimation()
    {
        FaceDirection();
        RunningAnim();
        JumpingAnim();
        FaillingAnim();
    }

    void FaceDirection()
    {
        if ((isFaceToRight && !sr.flipX) || (!isFaceToRight && sr.flipX))
        {
            return;
        }
        if (isFaceToRight)
        {
            sr.flipX = false;
        }
        else
        {
            sr.flipX = true;
        }
    }


    void RunningAnim()
    {
        if (isMoving)
        {
            anim.SetBool(runAnimID, true);
        }
        else
        {
            anim.SetBool(runAnimID, false);
        }
        
    }

    void JumpingAnim()
    {
        if (isJumping)
        {
            anim.SetBool(jumpAnimID, true);
        }
        else
        {
            anim.SetBool(jumpAnimID, false);
        }
    }

    void FaillingAnim()
    {
        if (isFalling)
        {
            anim.SetBool(fallAnimID, true);
        }
        else
        {
            anim.SetBool(fallAnimID, false);
        }
    }

}
